package com.chuangke.common.sqlparser;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public enum QcExpOperatorEnum {

    EQ("EQ", "="), NE("NE", "!="), GT("GT", ">"), GTE("GTE", ">="), LT("LT", "<"), LTE("LTE", "<="),
    LIKE("LIKE", "LIKE"), BETWEEN("BETWEEN", "BETWEEN"), IS("IS", "is");

    private String code;
    private String desc;

    QcExpOperatorEnum(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public static Map<String, Map<String, Object>> toMap() {
        QcExpOperatorEnum[] ary = QcExpOperatorEnum.values();
        Map<String, Map<String, Object>> enumMap = new HashMap<>();
        for (QcExpOperatorEnum qcExpOperatorEnum : ary) {
            Map<String, Object> map = new HashMap<>();
            String key = qcExpOperatorEnum.getCode();
            map.put("code", qcExpOperatorEnum.getCode());
            map.put("desc", qcExpOperatorEnum.getDesc());
            enumMap.put(key, map);
        }
        return enumMap;
    }

    @SuppressWarnings({"rawtypes", "unchecked"})
    public static List toList() {
        QcExpOperatorEnum[] ary = QcExpOperatorEnum.values();
        List list = new ArrayList();
        for (QcExpOperatorEnum qcExpOperatorEnum : ary) {
            Map<String, String> map = new HashMap<>();
            map.put("code", qcExpOperatorEnum.getCode());
            map.put("desc", qcExpOperatorEnum.getDesc());
            list.add(map);
        }
        return list;
    }

    public static QcExpOperatorEnum getEnum(String code) {
        QcExpOperatorEnum[] arry = QcExpOperatorEnum.values();
        for (QcExpOperatorEnum qcExpOperatorEnum : arry) {
            if (qcExpOperatorEnum.getCode().equalsIgnoreCase(code)) {
                return qcExpOperatorEnum;
            }
        }
        return null;
    }

    /**
     * 取枚举的json字符串
     *
     * @return
     */
    public static String getJsonStr() {
        QcExpOperatorEnum[] enums = QcExpOperatorEnum.values();
        StringBuilder jsonStr = new StringBuilder("[");
        for (QcExpOperatorEnum senum : enums) {
            if (!"[".equals(jsonStr.toString())) {
                jsonStr.append(",");
            }
            jsonStr.append("{code:'").append(senum.getCode()).append("',desc:'").append(senum.getDesc()).append("'}");
        }
        jsonStr.append("]");
        return jsonStr.toString();
    }
}
